package de.gora.prog2swing.adventskalender;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Time implements Runnable {
	
	private AdventCalendar frame;
	
	public Time(AdventCalendar calendar){
		this.frame = calendar;
	}

	public void run() {
		while(!Thread.interrupted()){
			setTitle();
			try{
				Thread.sleep(1000);
			} catch(InterruptedException e){
				
			}
			
		}
	}
	
	public void setTitle(){
		Date date = new Date();
		SimpleDateFormat 
			timef = new SimpleDateFormat("HH:mm:ss"),
			datef = new SimpleDateFormat("dd.MM.yyyy");
		frame.setTitle(String.format("Datum: %s Zeit: %s", timef.format(date), datef.format(date)));
	}

}
